﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Altbrot.Yawr.Player;

namespace PlayerTest
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        WMPLibPlayer MyStreamPlayer;

        public Window1()
        {
            InitializeComponent();

            MyStreamPlayer = new WMPLibPlayer();
            MyStreamPlayer.OnStatusTextChanged += new PlayerStatusChangedEventHandler(MyStreamPlayer_OnStatusTextChanged);
        }

        void MyStreamPlayer_OnStatusTextChanged(string status)
        {
            this.tbStatus.Text = status;
        }

        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            if (!String.IsNullOrEmpty(this.tbUrl.Text))
            {
                try
                {
                    Uri url = new Uri(this.tbUrl.Text);
                    MyStreamPlayer.Play(url);
                }
                catch (UriFormatException)
                {
                    this.tbStatus.Text = "Text not of type URI";
                } 
            }
        }

        private void btnPause_Click(object sender, RoutedEventArgs e)
        {
            MyStreamPlayer.Pause();
        }

        private void btnStop_Click(object sender, RoutedEventArgs e)
        {
            MyStreamPlayer.Stop();
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (MyStreamPlayer != null)
            {
                MyStreamPlayer.Dispose();
            }
        }
    }
}
